package com.oa.demo.server.system.service.impl;

import com.oa.demo.server.system.entity.TRoleAuth;
import com.oa.demo.server.system.mapper.TRoleAuthMapper;
import com.oa.demo.server.system.service.ITRoleAuthService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import com.oa.demo.common.exception.BaseAuthException;

/**
* <p>
*  服务实现类
* </p>
*
* @author kongbox
* @since 2020-11-30
*/
@Slf4j
@Service
public class TRoleAuthServiceImpl extends ServiceImpl<TRoleAuthMapper, TRoleAuth> implements ITRoleAuthService {

    @Override
    public Page<TRoleAuth> listTRoleAuthsByPage(int page, int pageSize, String factor) {
    log.info("正在执行分页查询tRoleAuth: page = {} pageSize = {} factor = {}",page,pageSize,factor);
    QueryWrapper<TRoleAuth> queryWrapper =  new QueryWrapper<TRoleAuth>().like("", factor);
    //TODO 这里需要自定义用于匹配的字段,并把wrapper传入下面的page方法
    Page<TRoleAuth> result = super.page(new Page<>(page, pageSize));
    log.info("分页查询tRoleAuth完毕: 结果数 = {} ",result.getRecords().size());
    return result;
    }

    @Override
    public TRoleAuth getTRoleAuthById(int id) {
    log.info("正在查询tRoleAuth中id为{}的数据",id);
    TRoleAuth tRoleAuth = super.getById(id);
    log.info("查询id为{}的tRoleAuth{}",id,(null == tRoleAuth?"无结果":"成功"));
    return tRoleAuth;
    }

    @Override
    public int insertTRoleAuth(TRoleAuth tRoleAuth) throws BaseAuthException {
    log.info("正在插入tRoleAuth");
    if (super.save(tRoleAuth)) {
    log.info("插入tRoleAuth成功,id为{}",tRoleAuth.getId());
    return tRoleAuth.getId();
    } else {
    log.error("插入tRoleAuth失败");
    throw new BaseAuthException("添加失败");
    }
    }

    @Override
    public int deleteTRoleAuthById(int id) throws BaseAuthException {
    log.info("正在删除id为{}的tRoleAuth",id);
    if (super.removeById(id)) {
    log.info("删除id为{}的tRoleAuth成功",id);
    return id;
    } else {
    log.error("删除id为{}的tRoleAuth失败",id);
    throw new BaseAuthException("删除失败[id=" + id + "]");
    }
    }

    @Override
    public int updateTRoleAuth(TRoleAuth tRoleAuth) throws BaseAuthException {
    log.info("正在更新id为{}的tRoleAuth",tRoleAuth.getId());
    if (super.updateById(tRoleAuth)) {
    log.info("更新d为{}的tRoleAuth成功",tRoleAuth.getId());
    return tRoleAuth.getId();
    } else {
    log.error("更新id为{}的tRoleAuth失败",tRoleAuth.getId());
    throw new BaseAuthException("更新失败[id=" + tRoleAuth.getId() + "]");
    }
    }

    }
